package ext.tianma.loginAuth;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.keycloak.adapters.servlet.KeycloakOIDCFilter;


public class ExtKeycloakOIDCFilter extends KeycloakOIDCFilter {
	@Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException
    {
		HttpServletRequest request = (HttpServletRequest) req;
		 HttpSession  session = request.getSession();
		 String sessionAuth = (String) session.getAttribute("Authorization");
//		String auth = request.getHeader("Authorization");
		String isFilter = (String) session.getAttribute("isFilter");
		if(sessionAuth!=null && "false".equals(isFilter)){//login.jsp go to windchill
			chain.doFilter(request, res);
		}else{
			super.doFilter(req, res, chain);
		}
	}

}
